@extends "main.html"

@block body

<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md4 layui-color-white">md2</div>

        <div class="layui-col-md4">
            <h2 style="text-align: center;">编辑资料</h2><br><br>
            <form class="layui-form">
                {{ csrf_field }}

                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" value="{{ data['id'] }}" readonly class="layui-input layui-hide">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">账户</label>
                    <div class="layui-input-inline">
                        <input type="text" name="account" value="{{ data['account'] }}" readonly class="layui-input layui-hide">
                    </div>
                    <div class="layui-form-mid layui-word-aux">{{ data['account'] }}</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="password" value="" autocomplete="off" placeholder="请输入内容" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="nickname" value="{{ data['nickname'] }}" lay-verify="required" autocomplete="off" placeholder="请输入内容" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">锁定</label>
                    <div class="layui-input-inline">
                        <select name="is_lock" id="is_lock">
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-col-md4 layui-color-white">md2</div>
    </div>
</div>

@endblock

@block js

<script>
    //Demo
    layui.use(['form', 'laydate'], function(){
        var form = layui.form;

        let is_lock_value = "{$data.is_lock}";
        $("#is_lock").find("option[value='"+is_lock_value+"']").attr('selected', true);

        form.render('select');

        //监听提交
        form.on('submit(formDemo)', function(data){
            //当前容器的全部表单字段，名值对形式：{name: value}
            // console.log(data.field);
            // layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: "{{ uri }}/update2",
                method: "put",
                data: data.field,
                dataType: "JSON",
                success: function (callback){
                    // console.log(callback);
                    layer.msg(callback.message);

                    if (callback.code === 1)
                    {
                        setTimeout(function(){
                            window.parent.location.reload();
                        }, 1500)
                    }
                }
            });

            return false;
        });
    });
</script>

@endblock